#ifndef _HUMANMANAGER_H
#define _HUMANMANAGER_H

#include "talk.h"
#include "human.h"

class HumanManager
{
	private:
		std::map<uint32, Human*> humanList;
		static HumanManager *instance;
		HumanManager()
		{
		}
		~HumanManager() {}

	public:
		static HumanManager* getInstance()
		{
			if(instance == NULL)
			{
				instance = new HumanManager;
				if(instance == NULL) return NULL;
				else return instance;
			}
			return instance;
		}
		static void delInstance()
		{
			delete instance;
		}
		Human* getHumanByID(uint32 id)
		{
			if(this->humanList.find(id) != this->humanList.end())
			{
				return this->humanList[id];
			}
			else return NULL;
		}
		bool pushHuman(Human* human)
		{
			if(human)
			{
				this->humanList.insert(std::make_pair(human->getID(), human));
				return true;
			}
			return false;
		}

		bool marriage(uint8 id1, uint8 id2)
		{
			Human *pHuman1 = getHumanByID(id1);
			Human *pHuman2 = getHumanByID(id2);
			if(pHuman1 && pHuman2)
			{
				if(pHuman1->setMarrage(id2) && pHuman2->setMarrage(id1))
				{
					std::cout << "marrage:" << pHuman1->getName() << " marry " << pHuman2->getName() << " !!" << std::endl;
					return true;
				}
				else
				{
					pHuman1->usetMarrage();
					pHuman2->usetMarrage();
				}
			}
			return false;
		}
};
#endif
